#include "dominion.h"
#include "dominion_helpers.h"
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include "rngs.h"
#include <math.h>
#include <stdlib.h>
#include <stdio.h>

#define DEBUG 0
#define NOISY_TEST 1

int checkfullDeckCount(int p, int card, struct gameState *post){
  int i, count;
  struct gameState pre;
  memcpy (&pre, post, sizeof(struct gameState));

  int r;
  r =  fullDeckCount(p, card, post);
  count = 0;
  for (i = 0; i < pre.deckCount[p]; i++){
     if (pre.deck[p][i] == card)
	count ++;
  }
  for (i = 0; i < pre.handCount[p]; i++){
     if (pre.hand[p][i] == card)
	count ++;
  }
  for (i = 0; i < pre.discardCount[p]; i++){
     if (pre.discard[p][i] == card)
	count++;
  }

  assert (r == count);

  assert(memcmp(&pre, post, sizeof(struct gameState)) == 0);
  return 0;
}

int main () {

  int i, n, p, r, card;
  
  int k[10] = {adventurer, council_room, feast, gardens, mine,
	       remodel, smithy, village, baron, great_hall};

  struct gameState G;

  printf ("Testing fullDeckCount.\n");

  printf ("RANDOM TESTS.\n");

  SelectStream(2);
  PutSeed(3);
  
  for (n = 0; n < 20; n++) {
    card = floor(Random() * 26);
    p = floor(Random() * 2);
    G.deckCount[p] = floor(Random() * MAX_DECK);
    G.discardCount[p] = floor(Random() * MAX_DECK);
    G.handCount[p] = floor(Random() * MAX_HAND);
    checkfullDeckCount(p, card, &G);
  }

  printf ("ALL TESTS OK\n");

  return 0;
}
